home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / SAT 2.3.8 / Demos / StepPlatform Demo ƒ / sPlatform.p < prev    next >
Text File  |  1995-09-03  |  3KB  |  126 lines

  1. (* Platform sprite, experimental faceless sprite *)
  2.  
  3. unit sPlatForm;
  4. interface
  5.     uses
  6. {$ifc UNDEFINED THINK_PASCAL}
  7.         Types, QuickDraw, Menus, Windows, TextEdit, Fonts, Dialogs, Memory, {}
  8. {$endc}
  9.         SAT, PlatformGlobals, sPlayerSprite;
  10.  
  11.     procedure InitPlatform;
  12.     procedure HandlePlatform (me: SpritePtr);
  13.     procedure HitPlatform (me: SpritePtr; him: PlSpritePtr);
  14.     procedure SetupPlatform (me: SpritePtr);
  15.  
  16. implementation
  17.  
  18.     procedure InitPlatform;
  19. (* nada*)
  20.     begin
  21.     end;
  22.  
  23.     procedure HandlePlatform (me: SpritePtr);
  24.     (*me->face = nil;*)
  25.     begin
  26.     end;
  27.  
  28.     procedure HitPlatform (me: SpritePtr; him: PlSpritePtr);
  29.         var
  30.             mini, i, min: Integer;
  31.             diff: array[0..5] of Integer;
  32.     begin
  33.         if (him^.task = @HandlePlayerSprite) then
  34.             begin
  35.                 diff[1] := -me^.hotRect2.top + (him^.hotRect2.bottom);        (* TtoB *)
  36.                 diff[2] := -him^.hotRect2.top + (me^.hotRect2.bottom);         (* BtoT *)
  37.                 diff[3] := -me^.hotRect2.left + (him^.hotRect2.right);        (* LtoR *)
  38.                 diff[4] := -him^.hotRect2.left + (me^.hotRect2.right);        (* RtoL *)
  39.                 mini := 0;
  40.                 min := 10000;
  41.                 for i := 1 to 4 do
  42.                     begin
  43.                         if (min > diff[i]) then
  44.                             begin
  45.                                 min := diff[i];
  46.                                 mini := i;
  47.                             end; (* if *)
  48.                     end;
  49.                 case mini of
  50.                     1: (*floor*)
  51.                         begin
  52.                             him^.action := Stand;
  53.                             him^.position.v := him^.position.v - diff[1] + 1;
  54.                             if (him^.speed.v > 0) then
  55.                                 him^.speed.v := 0;
  56.                             him^.speed.h := 0;
  57.                         end;
  58.                     2: (* ceiling *)
  59.                         begin
  60.                             him^.position.v := him^.position.v + diff[2] + 1;
  61.                             if (him^.speed.v < 0) then
  62.                                 him^.speed.v := -him^.speed.v;
  63.                         end;
  64.                     3: (*left*)
  65.                         begin
  66.                             him^.position.h := him^.position.h - diff[3] - 1;
  67.                             if (him^.speed.h > 0) then
  68.                                 him^.speed.h := -him^.speed.h;
  69.                         end;
  70.                     4: (*right*)
  71.                         begin
  72.                             him^.position.h := him^.position.h + diff[4] + 1;
  73.                             if (him^.speed.h < 0) then
  74.                                 him^.speed.h := -him^.speed.h;
  75.                         end;
  76.                 end; (* switch *)
  77.             end;
  78.     end;
  79.  
  80.     procedure SetupPlatform (me: SpritePtr);
  81.         var
  82.             r: Rect;
  83.             pol: PolyHandle;
  84.  
  85.     begin
  86.         me^.task := @HandlePlatform;
  87.         me^.hitTask := @HitPlatform;
  88.  
  89.         me^.face := nil; (* = faceless! *)
  90.         SetRect(me^.hotRect, 0, 0, 100, 16);
  91.         r := me^.hotRect;
  92.         OffsetRect(r, me^.position.h, me^.position.v);
  93.         SATSetPortBackScreen;
  94.         ForeColor(cyanColor);
  95.     {$ifc UNDEFINED THINK_PASCAL}
  96.         FillRect(r, qd.dkGray);
  97.     {$ELSEC}
  98.         FillRect(r, dkGray);
  99.     {$endc}
  100.  
  101.         pol := OpenPoly;
  102.         MoveTo(r.left, r.top);
  103.         LineTo(r.left + 5, r.top - 5);
  104.         LineTo(r.right + 5, r.top - 5);
  105.         LineTo(r.right, r.top);
  106.         LineTo(r.left, r.top);
  107.         LineTo(r.right, r.top);
  108.  
  109.         LineTo(r.right, r.bottom);
  110.         LineTo(r.right + 5, r.bottom - 5);
  111.         LineTo(r.right + 5, r.top - 5);
  112.         LineTo(r.right, r.top);
  113.  
  114.         ClosePoly;
  115.         ErasePoly(pol);
  116.         FramePoly(pol);
  117.         KillPoly(pol);
  118.  
  119.         r.top := r.top - 5;
  120.         r.right := r.right + 5;
  121.         SATBackChanged(r); (* Tell SAT to draw it when appropriate *)
  122.  
  123.         me^.layer := -me^.position.v;
  124.     end;
  125.  
  126. end.